# 0 leds
# 1 switches
# 2 seven segs
# 3 keypad
# 4 stepper motor
# just send the switches straight to the status
# and set the speed constant (default) for now

mtc0 $0, $12           # turn off interrupts

lui $s0, 0xFFFF        # set base address for leds
addi $s1, $s0, 0x0040  # set base address of the switches controller
addi $s2, $s0, 0x0080  # set base address for seven seg controller
addi $s3, $s0, 0x00C0  # set base address of the hex keypad controller
addi $s4, $s0, 0x0100  # set base address of the stepper motor controller

addi $t0, $0, 0x000F   # turn all seven segs on
lui $s5, 0x00F0        # set mask for write enables and no dots
sw $t0, 0($s2)         # turn all seven segs on
sw $s5, 4($s2)         # write zeros without dots

loop: lw $t0, 4($s3)   # get buttons count
sw $t0, ($s0)          # push to leds
andi $t0, $t0, 3       # get lower two bits
bne $t0, $0, l0        # if count%4 != 0
jal keypad             # update from the keypad
l0: jal switches       # check the switches
j loop                 # repeat

keypad: lw $t0, 0($s3) # load hexkeypad buffer
andi $t0, $t0, 0xFFFF  # get only latest four buttons
add $t1, $t0, $s5      # write enable for the seven segs
sw $t1, 4($s2)         # write to seven segs
sll $t0, $t0, 8        # shift the four buttons left 8 bits
sw $t0, 4($s4)         # set as stepper speed word
jr $ra

switches: lw $t0, ($s1)# load switches
sw $t0, ($s4)          # set stepper motor status
jr $ra
